<template>
    <div class="app-container">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>积分商品</span>
            </div>
            <div class="text item">
                <div class="el-card__body" style="background-color: rgb(243, 243, 243); padding: 10px 0px 0px;">
                    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                        <el-card shadow="never" style="margin-top: 10px;">
                            <div slot="header" class="clearfix">
                                <div class="card-title">基础设置</div>
                            </div>
                            <div class="text item">
                                <el-form-item label="商品分类:" prop="productLevel">
                                    <el-select clearable v-model="checkboxList" placeholder="请选择" style="width:250px">
                                        <el-option v-for="item in 4" :key="item" :value="item - 1">{{ item - 1
                                            }}</el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="优惠限制:" prop="productLevel">
                                    <el-switch v-model="form.delFlag">
                                    </el-switch>
                                </el-form-item>

                            </div>
                        </el-card>
                        <el-card shadow="never" style="margin-top: 20px;">
                            <div slot="header" class="clearfix">
                                商品设置
                            </div>
                            <el-form-item label="商品信息:" prop="productLevel">
                                <el-button type="default" size="mini" @click="handleAdd">选择商品</el-button>
                            </el-form-item>
                        </el-card>
                    </el-form>
                </div>
            </div>
            <el-button type="primary" size="mini" @click="submitForm">保存</el-button>
        </el-card>

        <!-- 添加或修改供应商商品对话框 -->
        <el-dialog :title="title" :visible.sync="open" append-to-body>
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                label-width="138px">
                <el-form-item label="商品名称或商品ID" prop="goodId">
                    <el-input v-model="queryParams.goodId" placeholder="请输入商品名称或商品ID" clearable
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
            <!-- <el-table v-loading="loading" :data="goodList" ref="singleTable" highlight-current-row
                @row-dblclick="rowClick2" @current-change="handleCurrentChange" style="width: 100%">
                <el-table-column width="35">
                    <template slot-scope="scope">
                        <el-radio class="radio" :label="scope.row" v-model="currentRow">{{ "" }}</el-radio>
                    </template>
</el-table-column>
<el-table-column label="ID" align="center" prop="deptName" />

<el-table-column label="名称" align="center" prop="deptName" />
<el-table-column label="成本价" align="center" prop="sort" />
<el-table-column label="库存" align="center" prop="status">
    <template slot-scope='{row}'>
                        {{ row.status == 0 ? '正常' : '停用' }}
                    </template>
</el-table-column>
<el-table-column label="商品来源" align="center" prop="delFlag">
    <template slot-scope='{row}'>
                        {{ row.delFlag == 0 ? '显示' : '隐藏' }}
                    </template>
</el-table-column>
</el-table>

<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
    @pagination="getList" />

<div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="submitForm">确 定</el-button>
    <el-button @click="cancel">取 消</el-button>
</div> -->
            <good-list></good-list>
        </el-dialog>
    </div>
</template>

<script>
import { goodClassifyList, goodClassifyDetail, goodclassifyAdd, goodclassifyEdit, goodclassifyDelete } from "@/api/system/goods/classify";
import { integralGoodList, integralGoodId, integralGoodAdd, integralGoodEdit, integralGoodDelete } from "@/api/pointsMall/goods";
import GoodList from "./components/goodList.vue";

export default {
    name: "Good",
    components: { GoodList },
    data() {
        return {
            order_module: [
                { name: '累计余额', num: 1939376.64, toolip: '累计所有平台产生的余额' },
                { name: '已使用', num: 1939376.64, toolip: '使用余额支付或使用余额抵扣统计' },
                { name: '会员账户余额', num: 1939376.64, toolip: '所有会员现有账户的余额' },
                { name: '已提现余额', num: 1939376.64, toolip: '已提现的账户累计余额' },
            ],
            checkboxList: '',
            activeName: 'first',
            currentRow: '',
            // 日期范围
            dateRange: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 供应商商品表格数据
            goodList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                deptName: null,
                sort: null,
                classifyImg: null,
                status: null,
                delFlag: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                productLevel: [
                    { required: true, message: "商品等级 1vip 3共享店主 4联创 5区域运营 6总裁不能为空", trigger: "blur" }
                ],
            }
        };
    },
    created() {
    },
    methods: {
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                deptName: null,
                sort: null,
                classifyImg: null,
                status: null,
                delFlag: null,
            };
            this.dateRange = [];
            this.resetForm("form");
        },
        uploadImg(v) {
            this.form.classifyImg = v
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        // handleSelectionChange(selection) {
        //     this.ids = selection.map(item => item.id)
        //     this.single = selection.length !== 1
        //     this.multiple = !selection.length
        // },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(this.multipleSelection);
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "商品选择";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            goodClassifyDetail(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改商品分类";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        goodclassifyEdit(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        goodclassifyAdd(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            console.log(row.id);

            // const ids = row.id || this.ids;

            // this.$modal.confirm('是否确认删除数据？').then(function () {
            //     return goodclassifyDelete(ids);
            // }).then(() => {
            //     this.getList();
            //     this.$modal.msgSuccess("删除成功");
            // }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('system/good/export', {
                ...this.queryParams
            }, `good_${new Date().getTime()}.xlsx`)
        },
        setCurrent(row) {
            this.$refs.singleTable.setCurrentRow(row);
        },
        handleCurrentChange(row) {
            this.currentRow = row;
        },
        rowClick2(row, column, event) {
            if (this.currentRow && row.date == this.currentRow.date) {
                this.setCurrent();
                this.currentRow = null;
            } else {
                this.currentRow = row;
            }
        },
    }
};
</script>
<style lang="less" scoped>
.app-container {
    width: 100%;
    height: 1005;
    background-color: #f8f8f8;


}
</style>
<style scoped>
.text {
    font-size: 14px;
}

.item {
    margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}

.box-card {
    width: 100%;
}
</style>